Vykreslovani radku v ListView a pohyb Image
Otázka od: Development
9. 6. 2004 19:39
Dobry den,
s Vasi pomoci bych rad nasel lepsi reseni, nez momentalne mam...
A.
Ideou kodu bylo, aby se kazdy sudy prichozi radek do LV barevne
odlisil od licheho. To same, co je nize uvedeno, jsem napsal i do
procedury ListView1CustomDrawSubItem. Ve Windows 98 vse fungovalo
bez problemu, v XP v pripade, ze LV neni aktivni v popredi, dojde
k vyplneni cele tabulky barvou podle dane podminky. V pripade, ze
vynecham proceduru ListView1CustomDrawItem, barvi se radky az od
sloupce SubItemu, avsak jiz korektne. Tak nevim, co s tim...
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
Rect : TRect;
begin
with (Sender as TCustomListView).Canvas do
begin
if (Item.Index mod 2) = 0 then
begin
Brush.Color := clRed;
FillRect(Rect);
end
else
Brush.Color := clWhite;
end; {with}
B.
Jeste jeden problemek. Mam ScrollBox a v nem Image. Rad bych klikem
na Image ten obrazek 'uchopil' a tahal s nim tak, jak taham mysi, ale
v ramci nejakych mantinelu (tedy abych Image nevytahl mimo ScrollBox).
Trochu to funguje s timhle, ale neni to ono, co bych chtel...
procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
DownX := X;
DownY := Y;
end;
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
with Sender as TImage do
begin
if Form1.ScrollBox1.Width < Form1.Image1.Width then
begin
if (X > DownX) and (X - DownX > 10) then
SendMessage(ScrollBox1.Handle, WM_HSCROLL, SB_LINELEFT, 0);
if (X < DownX) and (X - DownX < 10) then
SendMessage(ScrollBox1.Handle, WM_HSCROLL, SB_LINERIGHT, 0);
DownX := X;
end; {if}
if Form1.ScrollBox1.Height < Form1.Image1.Height then
begin
if (Y > DownY) and (Y - DownY > 10) then
SendMessage(ScrollBox1.Handle, WM_VSCROLL, SB_LINEUP, 0);
if (Y < DownY) and (Y - DownY < 10) then
SendMessage(ScrollBox1.Handle, WM_VSCROLL, SB_LINEDOWN, 0);
DownY := Y;
end; {if}
end; {with}
end;
--
Diky za pripadne nakopnuti, jsem s pozdravem,
M. Machacek, WXP, D6PE
Odpovedá: Ing. Slavomir Timko
10. 6. 2004 7:44
> Dobry den,
>
> s Vasi pomoci bych rad nasel lepsi reseni, nez momentalne mam...
>
> A.
>
> Ideou kodu bylo, aby se kazdy sudy prichozi radek do LV barevne
> odlisil od licheho. To same, co je nize uvedeno, jsem napsal i do
> procedury ListView1CustomDrawSubItem. Ve Windows 98 vse fungovalo
> bez problemu, v XP v pripade, ze LV neni aktivni v popredi, dojde
> k vyplneni cele tabulky barvou podle dane podminky. V pripade, ze
> vynecham proceduru ListView1CustomDrawItem, barvi se radky az od
> sloupce SubItemu, avsak jiz korektne. Tak nevim, co s tim...
>
> procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
> Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
> var
> Rect : TRect;
>
> begin
> with (Sender as TCustomListView).Canvas do
> begin
> if (Item.Index mod 2) = 0 then
> begin
> Brush.Color := clRed;
> FillRect(Rect);
> end
> else
> Brush.Color := clWhite;
> end; {with}
skus toto:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Odd(Item.Index) then Sender.Cavas.Brush.Color := clRed
else Sender.Cavas.Brush.Color := clWhite;
end;
a ak chces mat cely riadok jednej farby ListView1CustomDrawSubItem zmaz.
Slavo